const argv = process.argv.slice(2);
const fs = require('fs');
const path = require('path');
//数组转object
const getSentryInfo = () => {
  let obj = {};
  argv.map((item) => {
    if (item !== '') {
      const index = item.indexOf(':');
      if(index >= 0){
        obj[item.substr(0, index)] = item.substr(index + 1)
      }
    }
  });
  return obj;
}
let obj = getSentryInfo();



const getContent = (obj) => {
  return `{"${obj['env']}": {
    "weapp": "${obj['weapp']}",
    "host": "${obj['host']}",
    "magicHost": "${obj['magicHost']}",
    "magicPage": "${obj['magicPage']}",
    "renderHost": "${obj['renderHost']}",
    "ossHost": "${obj['ossHost']}",
    "pvUvHost": "${obj['pvUvHost']}",
    "wechatDsn": "${obj['wechatDsn']}",
    "mobileDsn": "${obj['mobileDsn']}"
  }}
`;
};
console.log('obj=>>>>>>',obj)
const content = getContent(obj);
console.log('content=>>>>>>',content)
fs.writeFile(path.resolve(__dirname, '.config.json'), content, (err) => {
  if (err) throw err;
  console.log('文件已被保存');
});
